﻿using System.Collections.Generic;
using System.Reflection;
using pub.Settings;

namespace scheduler
{
    internal class AppSettings : IniSettings
    {
        public AppSettings()
        {
            var iniFileName = Assembly.GetEntryAssembly().Location;
            iniFileName = iniFileName.Substring(0, iniFileName.LastIndexOf('.') + 1) + "ini";
            init(iniFileName);
        }

        public IList<string> LoadTodoLists()
        {
            var items = new List<string>();
            var sectionValues = this["TodoLists"].Entries;
            for (var n = 0; n < sectionValues.Count; n++)
            {
                var key = "Item" + (n + 1);
                if (!sectionValues.ContainsKey(key))
                {
                    break;
                }
                items.Add(sectionValues[key]);
            }
            return items;
        }

        public void SaveTodoLists(IList<string> items)
        {
            var settings = this["TodoLists"];
            settings.Clear();
            var count = items.Count;
            for (var n = 0; n < count; n++)
            {
                settings["Item" + (n + 1)].StringValue = items[n];
            }
        }

        public bool ShowOnStartup
        {
            get { return this["ShowOnStartup"].GetValue(true); }
            set { this["ShowOnStartup"].BoolValue = value; }
        }
    }
}